/*

* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Smart-Shop开源商城系统/ Java商城-首选电商平台系统 请务必保留此注释头信息
* |     开源地址: https://gitee.com/ningbo-qishan/gruul-mall
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     可正常分享和学习源码,未经授权 不可商用！
* |     商业版中台购买/开源版商业授权 联系技术客服
* |     官网:  https://www.73app.cn/
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Copyright (c) 2016-2999 宁波启山智软科技有限公司
* |     版权所有 ,侵权必究！
* ------------------------------------------------------------------------

*/
package com.medusa.gruul.platform.web.controller.agent;


import cn.dev33.satoken.annotation.SaCheckLogin;
import com.medusa.gruul.common.core.annotation.EscapeLogin;
import com.medusa.gruul.common.core.util.PageUtils;
import com.medusa.gruul.common.core.util.Result;
import com.medusa.gruul.platform.model.vo.agent.NoticeInfoVo;
import com.medusa.gruul.platform.model.vo.agent.NoticeInfosVo;
import com.medusa.gruul.platform.service.IAgentNoticeService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 代理商推送消息表结构 前端控制器
 * </p>
 *
 * @author whh
 * @since 2020-10-04
 */
@RestController
@RequestMapping("/agent/console/notice")
@SaCheckLogin
public class AgentNoticeController {

    @Autowired
    private IAgentNoticeService agentNoticeService;


    @GetMapping("/infos")
    @EscapeLogin
    @ApiOperation(value = "获取消息列表", tags = "代理管理台相关")
    public Result<PageUtils<NoticeInfosVo>> noticeInfos(@ApiParam(value = "指定页数", required = true) @RequestParam Integer page,
                                                        @ApiParam(value = "数据条数", required = true) @RequestParam Integer size,
                                                        @ApiParam(value = "消息标题查询") @RequestParam(required = false) String search,
                                                        @ApiParam(value = "搜索类型 type=0:全部 1:产品消息 2:财务消息 ")
                                                            @Range(min = 0, max = 2, message = "错误类型") @RequestParam Integer type
    ) {
        PageUtils<NoticeInfosVo> pageVos = agentNoticeService.noticeInfos(page, size, search, type);
        return Result.ok(pageVos);
    }

    @GetMapping("/detail/{id}")
    @EscapeLogin
    @ApiOperation(value = "获取消息详情", tags = "代理管理台相关")
    public Result<NoticeInfoVo> detail(@PathVariable Long id) {
        NoticeInfoVo vo = agentNoticeService.detail(id);
        return Result.ok(vo);
    }

}
